package org.ne.springboot.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;



/**
 * @author wey
 * md5加密工具类
 */
public class MD5Utils {


    /**
     *
     * @param str 原始密码
     * @return  buf 加密字符串
     * */
    public static String code(String str) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte[] byteDigest = md.digest();
            int i;
            StringBuilder buf = new StringBuilder();
            for (int offset = 0; offset < byteDigest.length; offset++) {
                i = byteDigest[offset];
                if(i<0)
                    i+=256;
                if (i<16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        System.out.println(code("111111"));
    }
}
